package honest.playmusic.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javazoom.jl.decoder.JavaLayerException;
/**
 * 
 * 单例模式
 */
import javazoom.jl.player.advanced.AdvancedPlayer;

public class MusicPlayerDecode {
	AdvancedPlayer player=null;
	private String filePath="";
	private MusicPlayerDecode(){

	}

	/**
	 * 得到解码器
	 * @return  解码器
	 */
	public AdvancedPlayer getPlayer(){
		if(player==null){
			try{
				player=new AdvancedPlayer(new FileInputStream(filePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (JavaLayerException e) {
				e.printStackTrace();
			}
		}
		return player;
	}

	/**
	 * 清除解码器(播放器)
	 */
	public void close(){
		player=null;
	}

	/**
	 * 设置文件路径
	 * @param filePath 文件路径
	 */
	public void setFilePath(String filePath){
		this.filePath=filePath;
	}
}
